package streamAPI.operators;

import org.apache.flink.streaming.api.collector.selector.OutputSelector;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import streamAPI.source.MyNoParallelSource;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yue.cao
 * @since 09-28-2020
 */
public class DemoWithSplit {

	public static void main(String[] args) throws Exception {
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		DataStreamSource<Long> stream = env.addSource(new MyNoParallelSource());

		stream.split(new OutputSelector<Long>() {
			@Override
			public Iterable<String> select(Long value) {
				List<String> outPutList = new ArrayList<String>();
				if (value % 2 == 0) {
					outPutList.add("偶数流");
				} else {
					outPutList.add("奇数流");
				}
				return outPutList;
			}
		}).select("奇数流").print().setParallelism(1);

		env.execute(DemoWithSplit.class.getName());

	}
}
